package package1;

import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFrame;

/**
 * Clase Sound
 * @author Luis Angel Arranz
 */
public class Sound extends JFrame {

    Clip clip;

    @SuppressWarnings("empty-statement")
    public Sound(String nombre, int veces) {
        
        File sf;
        AudioFileFormat aff;
        AudioInputStream ais;
        sf = new File(nombre);

        try {
            
            aff = AudioSystem.getAudioFileFormat(sf);
            ais = AudioSystem.getAudioInputStream(sf);
            AudioFormat af = aff.getFormat();
            DataLine.Info info = new DataLine.Info(
                Clip.class,
                ais.getFormat(),
                ((int) ais.getFrameLength()
                * af.getFrameSize()));
            clip = (Clip) AudioSystem.getLine(info);
            clip.open(ais);
            clip.loop(veces);
            //Clip.LOOP_CONTINUOUSLY 
            
        } catch (UnsupportedAudioFileException ee) {
        } catch (IOException ea) {
        } catch (LineUnavailableException lue) {
        };
    }

    public void stop() {
        clip.stop();
    }
    
}
